From: Jonathan Dieter Date: Mon, 4 Jun 2018 07:43:54 +0000 (+0300) Subject: Add function for copying an index item (used to for mapping from an old X-Git-Tag: archive/raspbian/1.1.9+ds1-1+rpi1~1^2~261 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=59084d96ae2051e79831e978f02ae6c69f3a8a00;p=zchunk.git Add function for copying an index item (used to for mapping from an old zchunk to a new) Signed-off-by: Jonathan Dieter --- diff --git a/src/lib/index/index_common.c b/src/lib/index/index_common.c index 0484cd9..30b9e9f 100644 --- a/src/lib/index/index_common.c +++ b/src/lib/index/index_common.c @@ -93,3 +93,26 @@ void zck_index_free(zckCtx *zck) { zck->header_digest = NULL; } } + +zckIndexItem *copy_index_item(zckIndexItem *src) { + zckIndexItem *dst = zmalloc(sizeof(zckIndexItem)); + if(dst == NULL) { + zck_log(ZCK_LOG_ERROR, "Unable to allocate %lu bytes\n", + sizeof(zckIndexItem)); + return NULL; + } + dst->digest = zmalloc(src->digest_size); + if(dst->digest == NULL) { + free(dst); + zck_log(ZCK_LOG_ERROR, "Unable to allocate %lu bytes\n", + src->digest_size); + return NULL; + } + memcpy(dst->digest, src->digest, src->digest_size); + dst->digest_size = src->digest_size; + dst->valid = src->valid; + dst->start = src->start; + dst->comp_length = src->comp_length; + dst->length = src->length; + return dst; +}